package jwd.base

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.widget.Toast

/**
 * Created by udi on 17-7-29.
 */
open class BaseActivity  @SuppressLint("ValidFragment") constructor(var activityId: Int = 0): AppCompatActivity() {

    /**
     * 设置 Fragement
     */
    fun setFragement(layoutId: Int, fragment: Fragment) {
        val ft = supportFragmentManager.beginTransaction()
        ft.replace(layoutId, fragment)
        ft.commit()
    }

    /**
     * 显示消息，自动关闭
     */
    fun showMessage(msg: String) {
        if( msg.isEmpty()){
            return;
        }

        Toast.makeText(applicationContext,  msg, Toast.LENGTH_LONG).show()
    }

    /**
     * 提示消息，需用户关闭。
     */

    fun alert(msg: String, title: String = "", buttonName: String = ""): AlertDialog {
        return AlertDialog.Builder(this)
                .setTitle(if (title.isBlank()) "提示" else title)
                .setMessage(msg)
                .setPositiveButton(if (buttonName.isBlank()) "确定" else buttonName, null)
                .show();
    }
}